import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

//瀑布流
class WatterFall {

  /// 普通瀑布流
  /// itemBuilder childs提供方法
  /// itemCount child数量
  /// crossAxisCount 几列
  /// mainAxisSpacing 横向间距
  /// crossAxisSpacing 垂直间距
  /// scrollController 控制器
  /// padding 整个外层间距
  /// scrollDirection 滚动方向,默认垂直
  static MasonryGridView listView({
    Key? key,
    required IndexedWidgetBuilder itemBuilder,
    required int itemCount,
    required int crossAxisCount,
    required double mainAxisSpacing,
    required double crossAxisSpacing,
    ScrollController? scrollController,
    EdgeInsetsGeometry? padding, //整个外层间距
    Axis? scrollDirection, //滚动方向,默认垂直
    bool? primary,
    bool shrinkWrap = false,
    ScrollPhysics? physics,
    double? cacheExtent,
  }) {
    return MasonryGridView.count(
      key: key,
      crossAxisCount: crossAxisCount,
      mainAxisSpacing: mainAxisSpacing,
      crossAxisSpacing: crossAxisSpacing,
      itemBuilder: itemBuilder,
      itemCount: itemCount,
      padding: padding ?? EdgeInsets.zero,
      scrollDirection: scrollDirection ?? Axis.vertical,
      controller: scrollController,
      primary: primary,
      shrinkWrap: shrinkWrap,
      physics: physics,
      cacheExtent: cacheExtent ?? 150,
    );
  }

  /// Sliver瀑布流
  /// itemBuilder childs提供方法
  /// itemCount child数量
  /// crossAxisCount 几列
  /// mainAxisSpacing 横向间距
  /// crossAxisSpacing 垂直间距
  static SliverMasonryGrid sliverView({
    Key? key,
    required int itemCount,
    required IndexedWidgetBuilder itemBuilder,
    required int crossAxisCount,
    required double mainAxisSpacing,
    required double crossAxisSpacing,
  }) {
    return SliverMasonryGrid.count(
      key: key,
      crossAxisCount: crossAxisCount,
      mainAxisSpacing: mainAxisSpacing,
      crossAxisSpacing: crossAxisSpacing,
      itemBuilder: itemBuilder,
      childCount: itemCount,
    );
  }
}